<!doctype html>
<head>
	<meta charset="utf-8">

	<title>JSO Demo</title>

	<!-- All JavaScript at the bottom, except this Modernizr build.
			 Modernizr enables HTML5 elements & feature detects for optimal performance.
			 Create your own custom Modernizr build: www.modernizr.com/download/ -->
	<script src="../../../cordova-1.5.0.js"></script>
	<script src="js/libs/childbrowser.js"></script>
	<script src="js/libs/json2.js"></script>
	<!-- https://github.com/wojodesign/local-storage-js -->
	<script src="js/libs/localstorage.js"></script>
	<script src="js/libs/modernizr-2.5.3.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

	<script src="../jso.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			
			
			if(window.plugins.childBrowser == null) {
	            ChildBrowser.install();
	        }

	        // Use ChildBrowser instead of redirecting the main page.
	        jso_registerRedirectHandler(window.plugins.childBrowser.showWebPage);

	        /*
	         * Register a handler on the childbrowser that detects redirects and
	         * lets JSO to detect incomming OAuth responses and deal with the content.
	         */
	         
	         
	        window.plugins.childBrowser.onLocationChange = function(url){
	            url = decodeURIComponent(url);
	            console.log("Checking location: " + url);
	            jso_checkfortoken('facebook', url, function() {
	                console.log("Closing child browser, because a valid response was detected.");
	                window.plugins.childBrowser.close();
	            });
	        };
	        
	        

			// Add configuration for one or more providers.
			jso_configure({
				"uwap": {
					client_id: "-----",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "http://proxydemo.app.bridge.uninett.no/_/oauth/auth.php/authorization"
				}
				,"facebook": {
					client_id: "-----",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "https://www.facebook.com/dialog/oauth",
					presenttoken: "qs"
				},
				"linkedin": {
					client_id: "-----",
					redirect_uri: "http://www.stud.hig.no/~090370/analysis/clicks_on.php",
					authorization: "https://www.linkedin.com/oauth"
				},
				"google": {
					client_id: "536722023927.apps.googleusercontent.com",
					redirect_uri: "http://www.stud.hig.no/~090370/nature/index.html",
					authorization: "https://accounts.google.com/o/oauth2/auth"
				},
				"ibm": {
					client_id: "-----.googleusercontent.com",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "https://accounts.google.com/o/oauth2/auth"
				},
				"solberg": {
					client_id: "andreas2",
					redirect_uri: "file://localhost/Users/andreas/Sites/jso/demo/index.html",
					authorization: "http://bridge.uninett.no/solberg-oauth/www/server/server.php/authorization"
				},
				"solberg2": {
					client_id: "andreas",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "http://bridge.uninett.no/solberg-oauth/www/server/server.php/authorization"
				},
				"solberg3": {
					client_id: "jsodemo",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "http://proxydemo.app.bridge.uninett.no/_/oauth/auth.php/authorization"
				},
				"instagram": {
					client_id: "xxx",
					redirect_uri: "http://localhost/~andreas/jso/demo/",
					authorization: "https://instagram.com/oauth/authorize/",
					scope: ["basic", "likes"],
					isDefault: true
				}
			});

			// if (!confirm('Continue')) return;

			// Make sure that you have 
			jso_ensureTokens({
				// "facebook": ["read_stream"],
				 "google": ["https://www.googleapis.com/auth/userinfo.profile"],
				//"instagram": ["basic", "likes"]
			});

			// This dumps all cached tokens to console, for easyer debugging.
			jso_dump();

			/*
			$.oajax({
				url: "http://www.facebook.com/dialog/oauth/?",
				jso_provider: "facebook", // Will match the config identifier
				jso_scopes: ["read_stream"], // List of scopes (OPTIONAL)
				dataType: 'json',
				success: function(data) {
					console.log("Response (facebook):");
					console.log(data);
				},
				error: function() {
					console.log("ERROR Custom callback()");
				}
			});
			*/
			
			// Perform a data request
			/*
			$.oajax({
				url: "https://api.instagram.com/v1/subscriptions",
				jso_provider: "instagram", // Will match the config identifier
				jso_scopes: false, // List of scopes (OPTIONAL)
				dataType: 'json',
				success: function(data) {
					console.log("Response (bridge):");
					console.log(data);
				},
				error: function() {
					console.log("ERROR Custom callback()");
				}
			});
			*/

			// Perform a data request
			 $.oajax({
			 	url: "https://accounts.google.com/o/oauth2/auth?",
			 	jso_provider: "google",
			 	jso_allowia: true,
			 	jso_scopes: ["https://www.googleapis.com/auth/userinfo.profile"],
			 	dataType: 'json',
			 	success: function(data) {
			 		console.log("Response (google):");
			 		console.log(data);
			 	}
			 });

			// jso_wipe();

		});
	</script>

</head>
<body>



</body>
</html>